import { BasicColumn, FormSchema } from '@/components/Table';
import { setRoleStatus } from '@/api/demo/system';
import { useMessage } from '@/hooks/web/useMessage';
import { uploadApi } from '/@/api/sys/upload';
import dayjs from 'dayjs';

export const columns: BasicColumn[] = [
  {
    title: '文件类型',
    dataIndex: 'extName',
    width: 80
  },
  {
    title: '文件名',
    dataIndex: 'roleName',
    align: 'left'
  },
  {
    title: '文件路径',
    dataIndex: 'roleValue',
    width: 280,
    align: 'left'
  },
  {
    title: '文件大小',
    dataIndex: 'orderNo',
    width: 80,
    align: 'left'
  },
  {
    title: '权限',
    dataIndex: 'orderNo',
    width: 80,
    align: 'left',
    customRender:({record}) => {
      if(record.status==0) {
        return '私有';
      } else if(record.status==1) {
        return '公共读';
      } else if(record.status==2) {
        return '租户公共读';
      }
    }
  },
  {
    title: '文件MD5',
    dataIndex: 'orderNo',
    width: 120
  },
  {
    title: '创建时间',
    dataIndex: 'id',
    width: 180,
    sorter: true,
    fixed: 'right',
    customRender: ({record})=>{
      return record.createTime;
    }
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: '[startDate, endDate]',
    label: '日期范围',
    labelWidth: 80,
    component: 'RangePicker',
    colProps: { xs: 24, md: 8, lg: 6 },
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['开始时间', '结束时间'],
      showTime: { format: 'HH:mm:ss' },
    },
    defaultValue:[dayjs(new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 7)).format('YYYY-MM-DD'),dayjs(new Date()).format('YYYY-MM-DD')]
  },
  {
    field: 'bucket',
    label: '桶名',
    labelWidth: 80,
    component: 'Select',
    componentProps: {
      options: [
        { label: 'Aliyun', value: 'aliyun' },
        { label: 'MinIO', value: 'minio' },
      ],
    },
    colProps: { xs: 24, md: 8, lg: 6  },
  },
  {
    field: 'format',
    label: '文件格式',
    labelWidth: 80,
    component: 'Select',
    componentProps: {
      options: [
        { label: '图片', value: 'image' },
        { label: 'Doc', value: 'doc' },
        { label: 'Excel', value: 'excel' },
        { label: 'Zip', value: 'zip' },
      ],
    },
    colProps: { xs: 24, md: 8, lg: 6  },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'bucket',
    label: '桶名',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: 'Aliyun', value: 'aliyun' },
        { label: 'MinIO', value: 'minio' },
      ],
    },
  },
  {
    label: '文件名',
    field: 'remark',
    component: 'Input',
  },
  {
    field: 'roleName',
    label: '文件路径',
    required: true,
    defaultValue: '/',
    component: 'Input',
  },
  {
    field: 'file',
    label: '文件',
    required: true,
    component: 'Upload',
    componentProps: {
      maxSize:20,
      maxNumber:1,
      multiple:false,
      showPreviewNumber:false,
      emptyHidePreview:true,
      api:uploadApi,
    }
  },

  {
    label: ' ',
    field: 'menu',
    slot: 'menu',
  },
];
